package com.hulk.dryad.manage.framework.datasource;

import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.hulk.dryad.manage.framework.tenant.TenantContextHolder;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.GenericFilterBean;

import javax.servlet.FilterChain;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 根据租户号手动指定当前数据源
 * @author hulk
 * @date 2020/9/13
 *
 */
@Slf4j
public class DynamicDataSourceHolder  {


	public static void set( String tenantId ) {
		if(StrUtil.isBlank(tenantId)){
			log.error("DynamicDataSourceHolder参数tenantId不能为空");
		}
		TenantContextHolder.setTenantId(tenantId);
		DynamicDataSourceContextHolder.clear();
		DynamicDataSourceContextHolder.push(tenantId);
	}

}
